import request from '@/utils/request'

// api地址
const api = {
  login: 'passport/login',
  loginMpWx: 'passport/loginMpWx',
  loginWxOfficial: 'passport/loginWxOfficial',
  loginMpWxMobile: 'passport/loginMpWxMobile',
}

// 用户登录 (手机号+验证码)
export function login(data) {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/passport/login',
      method: 'post',
      data
    }).then(data => {
      resolve(data)
    }).catch((e) => {
  		console.log(e);
      reject(e)
    })
  })
}

// 微信小程序快捷登录 (获取微信用户基本信息)
export function loginMpWx(data, option) {
  return new Promise((resolve, reject) => {
    request({
      url: '/api/passport/loginMpWx',
      method: 'post',
      data,
	   ...option
    }).then(data => {
      resolve(data)
    }).catch((e) => {
  		console.log(e);
      reject(e)
    })
  })
}

// 微信公众号一键授权登录 (获取微信用户基本信息)
export function loginWxOfficial(data, option) {
 return new Promise((resolve, reject) => {
    request({
      url: '/api/passport/loginWxOfficial',
      method: 'post',
      data,
  	   ...option
    }).then(data => {
      resolve(data)
    }).catch((e) => {
  		console.log(e);
      reject(e)
    })
  })
}

// 微信小程序快捷登录 (授权手机号)
export function loginMpWxMobile(data, option) {
 return new Promise((resolve, reject) => {
    request({
      url: '/api/passport/loginMpWxMobile',
      method: 'post',
      data,
  	   ...option
    }).then(data => {
      resolve(data)
    }).catch((e) => {
  		console.log(e);
      reject(e)
    })
  })
}
